﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Camelot.SharePointIntegration.Client;

namespace Examples
{
    /// <summary>
    /// Reads compressed CamelotXml file into a ListData object and prints some information about the content
    /// </summary>
    class ReadCamelotXmlCompressedToListData
    {
        public static void DoIt(string cmpFile)
        {
            var xml = System.IO.File.ReadAllBytes(cmpFile).DeflateDecompress();
            var data = Camelot.SharePointIntegration.Client.CamelotXml.ReadXml(xml);

            if (data.Description != null)
            {
                Console.WriteLine("Description");
                Console.WriteLine("  Id: " + data.Description.ID);
                Console.WriteLine("  Title: " + data.Description.Title);
                Console.WriteLine("  Type: " + data.Description.BaseType);
                Console.WriteLine("  Number of items: " + data.Description.ItemCount);
                Console.WriteLine("  Created: " + data.Description.Created);
                Console.WriteLine("  Last modified: " + data.Description.Modified);
                Console.WriteLine();
            }

            if (data.Schema != null)
            {
                Console.WriteLine("Columns");

                foreach (System.Data.DataRow col in data.Schema.Rows)
                    Console.WriteLine("  " + col["DisplayName"] + " (" + col["Type"] + ")");
            }
            else
            {
                Console.WriteLine("Columns");

                foreach (System.Data.DataColumn col in data.Rows.Columns)
                    Console.WriteLine("  " + col.ColumnName + " (" + col.DataType.Name + ")");
            }
        }
    }
}
